// 选择器默认自定义options
export const fieldNames = {
  value: 'id',
  label: 'name',
  children: 'children'
}

// 组件配置
export const config = [
  {
    type: 'input',
    component: 'a-input',
    config: 'inputConfig'
  },
  {
    type: 'number',
    component: 'a-input-number',
    config: 'numberConfig'
  },
  {
    type: 'textarea',
    component: 'a-textarea',
    config: 'textareaConfig',
    autoSize: true
  },
  {
    type: 'select',
    component: 'a-select',
    config: 'selectConfig',
    showSearch: true, // 是否开启搜索
    fieldNames
  },
  {
    type: 'tree',
    component: 'a-tree-select',
    config: 'selectConfig',
    fieldNames,
    treeLine: true,
    showSearch: true,
    selectable: false,
    treeDefaultExpandAll: true,
    dropdownStyle: { maxHeight: '400px', overflow: 'auto' }
  },
  {
    type: 'date',
    component: 'a-date-picker',
    config: 'dateConfig',
    format: 'YYYY-MM-DD',
    valueFormat: 'YYYY-MM-DD'
  },
  {
    type: 'range',
    component: 'a-range-picker',
    config: 'dateConfig',
    p: ['开始时间', '结束时间'],
    format: 'YYYY-MM-DD',
    valueFormat: 'YYYY-MM-DD'
  },
  {
    type: 'range-time',
    component: 'a-range-picker',
    config: 'dateConfig',
    format: 'YYYY-MM-DD HH:mm:ss',
    valueFormat: 'YYYY-MM-DD HH:mm:ss',
    p: ['开始时间', '结束时间'],
    showTime: true
  },
  {
    type: 'upload',
    component: 'a-upload',
    config: 'uploadConfig',
    showUploadList: false
  }
]

// props：获取父传子配置参数
export const propsConfig = {
  // 展开
  expand: { type: Boolean, default: false },
  // 表单配置
  form: { type: Array, default: null },
  formParam: { type: Object, required: true, default: () => ({}) },
  formConfig: { type: Object, default: () => ({}) },
  // 选择器options，具体看demo
  /**
   * 父组件使用<v-table :optionConfig="{selectOptions: []}"/>
   */
  optionConfig: { type: Object, default: () => ({}) },
  // 根据条件禁用表单的集合对象，根据columns数组disabled是字符串条件返回，
  /**
   * 父组件使用<v-table :disabledConfig="{name:userId, address:userId == 1}"/>
   * disabledKeys：需要对比当前行的字段
   */
  disabledConfig: { type: Object, default: () => ({}) },
  // antd 输入框/选择器默认配置，具体看antd官网，可不使用
  inputConfig: { type: Object, default: () => ({}) },
  numberConfig: { type: Object, default: () => ({}) },
  textareaConfig: { type: Object, default: () => ({}) },
  selectConfig: { type: Object, default: () => ({}) },
  dateConfig: { type: Object, default: () => ({}) },
  uploadConfig: { type: Object, default: () => ({}) }
}

/**
 * data 为字符串时，通过 config 获取对应的配置
 * data 不满足条件时则返回本身
 */
export const findConfig = (data, config, type = 'string') => {
  return typeof data === type ? config[data] : data
}

// 搜索条件过滤
export const filterOption = (input, option, searchKey = 'name') => {
  return option[searchKey].toUpperCase().indexOf(input.toUpperCase()) >= 0
}

// 效验规则提示
export const rulesMessage = {
  input: '请输入',
  textarea: '请输入',
  select: '请选择',
  tree: '请选择',
  number: '请输入',
  date: '请选择',
  range: '请选择',
  'range-time': '请选择',
  upload: '请上传'
}
